#pragma once
#include "stdafx.h"
#include "ToyotaComm.h"
#include "ToyotaReadFile.h"
#include "ToyotaPJ.h"
#include "ToyotaSysP.h"
#include "ToyotaCDSF.h"

_BYTE byte_17512[10] = { 1, 3, 7, 0xF, 0x1F, 0x3F, 0x7F, 0xFF, 0, 0 };




unsigned __int16 CaculateBit(unsigned int CalVal1, unsigned int CalVal2, unsigned __int8 *pRcv, int a4, int *ResultVal)
{
	unsigned int v6; // r6
	unsigned int v7; // r7
	signed int v8; // r8
	unsigned int v9; // lr
	int v10; // r3
	unsigned int v11; // r7
	unsigned int v12; // r5
	unsigned __int8 *v13; // r6
	int v14; // t1
	char v15; // r4
	int v16; // r0

	if (CalVal2 < CalVal1)
		return -1;
	v6 = CalVal2 >> 3;
	v7 = ~CalVal2 & 7;
	v8 = (CalVal2 >> 3) - (CalVal1 >> 3);
	v9 = CalVal1 >> 3;
	v10 = pRcv[CalVal2 >> 3] >> v7;
	*ResultVal = v10;
	if (v8 >= 2)
	{
		v11 = 8 - v7;
		v12 = v9 + 1 - v6;
		v13 = &pRcv[v6 - 1];
		do
		{
			v14 = *v13--;
			v15 = v11;
			v11 += 8;
			++v12;
			v10 |= v14 << v15;
			*ResultVal = v10;
		} while (v12);
	}
	if (v8 <= 0)
		v16 = (unsigned __int8)(byte_17512[CalVal2 - CalVal1] & v10);
	else
		v16 = (pRcv[v9] << (CalVal1 & 7) << (-7 - CalVal1 + CalVal2)) | v10;
	*ResultVal = v16;
	return 0;
}



